﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using ElementumForever.Interfaces;
using ElementumForever.Factory;
using ElementumForever.Editer;

namespace ElementumForever.CommandPattern
{
    class AddObjectCommand : ICommand
    {

        string name;
        string _class;
        float width, height, originX, originY, positionX, positionY, scale, rotation;
        Color color;
        BaseEntity parent;
        string id;
        BaseEntity entity;

        public AddObjectCommand(BaseEntity parent,EntityPropertyProxy properties) {
        }

        public AddObjectCommand(BaseEntity parent, string name, string _class,float width, float height, float OriginX, float OriginY,float scale, float rotation, float PositionX, float PositionY, Color color)
        {
            this.parent = parent;
            this.name = name;
            this._class = _class;
            this.width = width;
            this.height = height;
            this.originX = OriginX;
            this.originY = OriginY;
            this.scale = scale;
            this.rotation = rotation;
            this.positionX = PositionX;
            this.positionY = PositionY;
            this.color = color;
        }

        public void Execute(IsceneBuilder builder)
        {
            if (builder.ContainId(id))
                throw new Exception("id:" + id + "already exists");
            entity = LuaFactory.CreatObject(name, _class, width, height, originX, originY, scale, positionX, positionY, rotation, color);
            id=builder.AddProduct(entity);
            builder.AttachChildById(id, parent);
        }

        public void UnExecute(IsceneBuilder builder)
        {
            if (builder.ContainId(id))
                builder.DetachChildById(id, parent);
            builder.RemoveProduct(id);
        }
    }
}
